#include "Kernel_PCH.h"
#include "Input.h"

/*--------------------------------------------------------------------------*/

IInput* g_Input = NULL;

/*--------------------------------------------------------------------------*/

CInput::CInput() :
	m_numEvents(0)
{
	m_statePtn = SDL_GetKeyboardState(&m_numStates);
}

/*--------------------------------------------------------------------------*/

CInput::~CInput()
{

}

/*--------------------------------------------------------------------------*/

void CInput::Capture()
{
	m_numEvents = 0;

	while (SDL_PollEvent(&m_events[m_numEvents]))
	{
		if (m_events[m_numEvents].type == SDL_QUIT)
		{
			g_Kernel->Close();
		}

		++m_numEvents;

		if (m_numEvents >=	SDL_EVENTS_BUFFER_SIZE)
		{
			__Crash("SDL buffer overflow");
		}
	}
}

/*--------------------------------------------------------------------------*/

bool CInput::GetKeyState( SDL_Keycode key )
{
	if (key & SDLK_SCANCODE_MASK)
	{
		return m_statePtn[key & ~(1<<30)];
	}
	else
	{
		return m_statePtn[SDL_GetScancodeFromKey(key & ~(1<<30))];
	}
}

/*--------------------------------------------------------------------------*/